import 'package:flutter/material.dart';
import 'package:st_liveness_detector/st_liveness_detector.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String status = '';
  var bytes;

  var result;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: ElevatedButtonTheme(
            data: ElevatedButtonThemeData(
              style: ElevatedButton.styleFrom(),
            ),
            child: Column(
              children: [
                getImage(),
                ElevatedButton(
                  onPressed: () async {
                    print(await StLivenessDetector.checkPermission());
                  },
                  child: const Text("权限监测"),
                ),
                ElevatedButton(
                  onPressed: () async {
                    print(await StLivenessDetector.startDetect());
                  },
                  child: const Text("开始监测"),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  getImage() {
    if (result == null) {
      return Container();
    } else {
      return Image.memory(result);
    }
  }
}
